package com.jht.pj.sys.service.impl;

import com.jht.pj.common.exception.ServiceException;
import com.jht.pj.common.pojo.PageObject;
import com.jht.pj.sys.dao.SongDao;
import com.jht.pj.sys.pojo.Song;
import com.jht.pj.sys.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SongServiceImpl implements SongService {

    @Autowired
    private SongDao songDao;

    @Override
    public List<Song> findSong() {
        List<Song> list = songDao.findSong();
        return list;
    }

    @Override
    public List<Song> findSongById(Integer id) {
        return songDao.findSongById(id);
    }

    @Override
    public List<Song> findSongByName(String name) {
        return songDao.findSongByName(name);
    }

    @Override
    public int countSong() {
        int rows = songDao.countSong();
        return rows;
    }

    @Override
    public PageObject<Song> findPageSong(Integer pageCurrent) {
        if(pageCurrent==null||pageCurrent<1)
            throw new IllegalArgumentException("页码值不合法");
        int rowCount = songDao.countSong();
        if (rowCount==0)
            throw new ServiceException("没有找到对应记录");
        int pageSize=3;
        int startIndex=(pageCurrent-1)*pageSize;
        List<Song> records = songDao.findPageSong(startIndex,pageSize);
        return new PageObject<>(rowCount,records,pageSize,pageCurrent);
    }



    /*@Override
    public List<Song> findSongByConcat(String name) {
        return songDao.findSongByConcat(name);
    }*/
}
